clear all

*********Set working directory and load data
local user: env USERNAME
if "`user'" == "ENTERYOURNAME"  cd "SETYOURDIRECTORY"
else if "`user'" == "sagomm"  cd "C:\Users\sagomm\Dropbox\SEP-Trust\Analysis\" 

use "Data\w9_conjoint.dta"

******Install necesarry user-written commands
do "Scripts\functions\function_conjoint.do"
do "Scripts\functions\function_addplot.do"


*************************************************************************	
*                                CHOICE                                 *
*                          Actors - Interaction                         *
*                                                                       *
*************************************************************************

************ Trust in institutions *******
loc ylab 0.2(.2).8

//Actor&Trust Interaction
qui reg choice ///
	ib1.actor##c.trust_inst ///
	regulation monitoring sanction reporting year, cluster(PubId)
eststo int_lr

	
*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est rest int_lr
qui margins, at(trust_inst=(-2(1)2) actor=(1(1)7)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Trust in institutions", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh) color(%10)) ///
	ci2opts(lc(maroon) color(%10)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th) color(%10)) ///
	ci3opts(lc(forest_green) color(%10)) ///
	plot4opts(lc(dkorange) mc(dkorange) m(Sh) color(%10)) ///
	ci4opts(lc(dkorange) color(%10)) ///
	plot5opts(lc(gray) mc(gray) m(Dh)) ///
	ci5opts(lc(gray)) ///
	plot6opts(lc(gs3) mc(gs3) m(Oh) color(%10)) ///
	ci6opts(lc(gs3) color(%10)) ///
	plot7opts(lc(black) mc(black) m(Th) lwidth(0.5)) ///
	ci7opts(lc(black)) ///
	ytitle("Pr(Selecting proposal)", s(small)) ///
	ylab("`ylab'",format(%3.2f) nogrid labs(vsmall)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labs(vsmall)) ///
	xti("") ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	graphregion(color(white)) ///
	legend(off) ///
	name(int_actors_trustinst, replace) 

est rest int_lr
margins, at(trust_inst=(-2(1)2) actor=(1(1)7)) post
mat list r(b)
test 1._at - 21._at = 0  // Actor = 1 at -2, and Actor = 5 at -2
test 2._at - 22._at = 0  // Actor = 1 at -1, and Actor = 5 at -1
test 3._at - 23._at = 0  // Actor = 1 at 0, and Actor = 5 at -0
test 4._at - 24._at = 0  // Actor = 1 at 1, and Actor = 5 at 2
test 5._at - 25._at = 0  // Actor = 1 at 2, and Actor = 5 at 2

test 1._at - 31._at = 0  // Actor = 1 at -2, and Actor = 7 at -2
test 2._at - 32._at = 0  // Actor = 1 at -1, and Actor = 7 at -1
test 3._at - 33._at = 0  // Actor = 1 at 0, and Actor = 7 at -0
test 4._at - 34._at = 0  // Actor = 1 at 1, and Actor = 7 at 2
test 5._at - 35._at = 0  // Actor = 1 at 2, and Actor = 7 at 2

*********** Trust in universities *******
loc ylab 0.2(.2).8

//Interaction - Actor&Trust
qui reg choice ///
	ib1.actor##c.trust_univ ///
	regulation monitoring sanction reporting year, cluster(PubId)
eststo int_lr

	
*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est rest int_lr
qui margins, at(trust_univ=(-2(1)2) actor=(1(1)7)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Trust in universities", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh) color(%10)) ///
	ci1opts(lc(edkblue) color(%10)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th) color(%10)) ///
	ci3opts(lc(forest_green) color(%10)) ///
	plot4opts(lc(dkorange) mc(dkorange) m(Sh) color(%10)) ///
	ci4opts(lc(dkorange) color(%10)) ///
	plot5opts(lc(gray) mc(gray) m(Dh) color(%10)) ///
	ci5opts(lc(gray) color(%10)) ///
	plot6opts(lc(gs3) mc(gs3) m(Oh)) ///
	ci6opts(lc(gs3)) ///
	plot7opts(lc(black) mc(black) m(Th) lwidth(0.5)) ///
	ci7opts(lc(black)) ///
	ytitle(" ", s(small)) ///
	ylab("`ylab'",format(%3.2f) nogrid labs(vsmall)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labs(vsmall)) ///
	xti("") ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	graphregion(color(white)) ///
	legend(off) ///
	name(int_actors_trustuniv, replace) 


	
************ Trust in NGOs *******
loc ylab 0.2(.2).8

////Actor&Trust Interaction
qui reg choice ///
	ib1.actor##c.trust_ngo ///
	regulation monitoring sanction reporting year, cluster(PubId)
eststo int_lr

	
*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est rest int_lr
qui margins, at(trust_ngo=(-2(1)2) actor=(1(1)7)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Trust in NGOs", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh) color(%10)) ///
	ci1opts(lc(edkblue) color(%10)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh) color(%10)) ///
	ci2opts(lc(maroon) color(%10)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	plot4opts(lc(dkorange) mc(dkorange) m(Sh) color(%10)) ///
	ci4opts(lc(dkorange) color(%10)) ///
	plot5opts(lc(gray) mc(gray) m(Dh) color(%10)) ///
	ci5opts(lc(gray) color(%10)) ///
	plot6opts(lc(gs3) mc(gs3) m(Oh)) ///
	ci6opts(lc(gs3)) ///
	plot7opts(lc(black) mc(black) m(Th) lwidth(0.5)) ///
	ci7opts(lc(black)) ///
	ytitle("Pr(Selecting proposal)", s(small)) ///
	ylab("`ylab'",format(%3.2f) nogrid labs(vsmall)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labs(vsmall)) ///
	xti("") ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	graphregion(color(white)) ///
	legend(off) ///
	name(int_actors_trustngo, replace) 


************ Trust in Industry *******
loc ylab 0.2(.2).8

//Actor&Trust Interaction
qui reg choice ///
	ib1.actor##c.trust_industry ///
	regulation monitoring sanction reporting year, cluster(PubId)
eststo int_lr

	
*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est rest int_lr
qui margins, at(trust_industry=(-2(1)2) actor=(1(1)7)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Trust in industry", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh) color(%10)) ///
	ci1opts(lc(edkblue) color(%10)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh) color(%10)) ///
	ci2opts(lc(maroon) color(%10)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th) color(%10)) ///
	ci3opts(lc(forest_green) color(%10)) ///
	plot4opts(lc(dkorange) mc(dkorange) m(Sh)) ///
	ci4opts(lc(dkorange)) ///
	plot5opts(lc(gray) mc(gray) m(Dh)) ///
	ci5opts(lc(gray)) ///
	plot6opts(lc(gs3) mc(gs3) m(Oh)) ///
	ci6opts(lc(gs3)) ///
	plot7opts(lc(black) mc(black) m(Th) lwidth(0.5)) ///
	ci7opts(lc(black)) ///
	ytitle(" ", s(small))  ///
	ylab("`ylab'",format(%3.2f) nogrid labs(vsmall)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labs(vsmall)) ///
	xti("") ///
	legend( ///
	pos(6) size(small) row(2)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	graphregion(color(white)) ///
	legend(off) ///
	name(int_actors_trustindustry, replace) 

*Note: Add in Latex 
*Marginal means from conjoint experiment for the dimension 'actors involved in the policy design process'. Dependent variable is the choice based on preference towards a policy proposal (A or B). Marginal means are conditioned by subgroups of different types of trust towards these actors (−2 s.d. to +2 s.d.). The grey dashed line denotes the 50% probability of selecting a proposal with the given characteristics controlling for all other policy dimensions. Error bars in represent 95% confidence intervals (df=`df') from `n' respondents * 5 choices for n=`obs' observations
	

gr combine ///
	int_actors_trustinst ///
	int_actors_trustuniv ///
	int_actors_trustngo ///
	int_actors_trustindustry, ///
	col (2) ///
	note("",  ///
	s(tiny) pos(7)) ///
	graphregion(color(white)) ///
	imargin(0 0 0 0) ///
	name(fig_trust_actors, replace)

graph di, ysize(10) xsize(6)
	
//Save Figure 
graph export "Plots\Figure3a_interaction_choice.png", name("fig_trust_actors") replace

graph export "Plots\Figure3a_interaction_choice.pdf", as(pdf) name("fig_trust_actors") replace		
	

*************************************************************************	
*                                BINARY                                 *
*                          Actors - Interaction                         *
*                                                                       *
*************************************************************************

************ Trust in institutions *******
loc ylab 0.2(.2).8

//Actor&Trust Interaction
qui reg binary ///
	ib1.actor##c.trust_inst ///
	regulation monitoring sanction reporting year, cluster(PubId)
eststo int_lr

	
*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est rest int_lr
qui margins, at(trust_inst=(-2(1)2) actor=(1(1)7)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Trust in institutions", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh)) ///
	ci1opts(lc(edkblue)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh) color(%10)) ///
	ci2opts(lc(maroon) color(%10)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th) color(%10)) ///
	ci3opts(lc(forest_green) color(%10)) ///
	plot4opts(lc(dkorange) mc(dkorange) m(Sh) color(%10)) ///
	ci4opts(lc(dkorange) color(%10)) ///
	plot5opts(lc(gray) mc(gray) m(Dh)) ///
	ci5opts(lc(gray)) ///
	plot6opts(lc(gs3) mc(gs3) m(Oh) color(%10)) ///
	ci6opts(lc(gs3) color(%10)) ///
	plot7opts(lc(black) mc(black) m(Th) lwidth(0.5)) ///
	ci7opts(lc(black)) ///
	ytitle("Pr(Selecting proposal)", s(small)) ///
	ylab("`ylab'",format(%3.2f) nogrid labs(vsmall)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labs(vsmall)) ///
	xti("") ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	graphregion(color(white)) ///
	legend(off) ///
	name(int_actors_trustinst, replace) 
	
*********** Trust in universities *******
loc ylab 0.2(.2).8

//Interaction - Actor&Trust
qui reg binary ///
	ib1.actor##c.trust_univ ///
	regulation monitoring sanction reporting year, cluster(PubId)
eststo int_lr

	
*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est rest int_lr
qui margins, at(trust_univ=(-2(1)2) actor=(1(1)7)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Trust in universities", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh) color(%10)) ///
	ci1opts(lc(edkblue) color(%10)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh)) ///
	ci2opts(lc(maroon)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th) color(%10)) ///
	ci3opts(lc(forest_green) color(%10)) ///
	plot4opts(lc(dkorange) mc(dkorange) m(Sh) color(%10)) ///
	ci4opts(lc(dkorange) color(%10)) ///
	plot5opts(lc(gray) mc(gray) m(Dh) color(%10)) ///
	ci5opts(lc(gray) color(%10)) ///
	plot6opts(lc(gs3) mc(gs3) m(Oh)) ///
	ci6opts(lc(gs3)) ///
	plot7opts(lc(black) mc(black) m(Th) lwidth(0.5)) ///
	ci7opts(lc(black)) ///
	ytitle(" ", s(small)) ///
	ylab("`ylab'",format(%3.2f) nogrid labs(vsmall)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labs(vsmall)) ///
	xti("") ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	graphregion(color(white)) ///
	legend(off) ///
	name(int_actors_trustuniv, replace) 


	
************ Trust in NGOs *******
loc ylab 0.2(.2).8

////Actor&Trust Interaction
qui reg binary ///
	ib1.actor##c.trust_ngo ///
	regulation monitoring sanction reporting year, cluster(PubId)
eststo int_lr

	
*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est rest int_lr
qui margins, at(trust_ngo=(-2(1)2) actor=(1(1)7)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Trust in NGOs", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh) color(%10)) ///
	ci1opts(lc(edkblue) color(%10)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh) color(%10)) ///
	ci2opts(lc(maroon) color(%10)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th)) ///
	ci3opts(lc(forest_green)) ///
	plot4opts(lc(dkorange) mc(dkorange) m(Sh) color(%10)) ///
	ci4opts(lc(dkorange) color(%10)) ///
	plot5opts(lc(gray) mc(gray) m(Dh) color(%10)) ///
	ci5opts(lc(gray) color(%10)) ///
	plot6opts(lc(gs3) mc(gs3) m(Oh)) ///
	ci6opts(lc(gs3)) ///
	plot7opts(lc(black) mc(black) m(Th) lwidth(0.5)) ///
	ci7opts(lc(black)) ///
	ytitle("Pr(Selecting proposal)", s(small)) ///
	ylab("`ylab'",format(%3.2f) nogrid labs(vsmall)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labs(vsmall)) ///
	xti("") ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	graphregion(color(white)) ///
	legend(off) ///
	name(int_actors_trustngo, replace) 

************ Trust in Industry *******
loc ylab 0.2(.2).8

//Actor&Trust Interaction
qui reg binary ///
	ib1.actor##c.trust_industry ///
	regulation monitoring sanction reporting year, cluster(PubId)
eststo int_lr

	
*Save n and degress of freedom
loc obs1=e(N)
loc obs:di %7.0fc `obs1'
loc n1=e(N_clust)
loc n:di %6.0fc `n1'
loc df1=e(df_r)
loc df:di %6.0fc `df1'

est rest int_lr
qui margins, at(trust_industry=(-2(1)2) actor=(1(1)7)) post
eststo int_mar_lr_size
est res int_mar_lr_size
marginsplot, ///
	title("Trust in industry", ///
	bex box bc(gs14) lc(black) lp(solid) bm(small)) ///
	plot1opts(lc(edkblue) mc(edkblue) m(Dh) color(%10)) ///
	ci1opts(lc(edkblue) color(%10)) ///
	plot2opts(lc(maroon) mc(maroon) m(Oh) color(%10)) ///
	ci2opts(lc(maroon) color(%10)) ///
	plot3opts(lc(forest_green) mc(forest_green) m(Th) color(%10)) ///
	ci3opts(lc(forest_green) color(%10)) ///
	plot4opts(lc(dkorange) mc(dkorange) m(Sh)) ///
	ci4opts(lc(dkorange)) ///
	plot5opts(lc(gray) mc(gray) m(Dh)) ///
	ci5opts(lc(gray)) ///
	plot6opts(lc(gs3) mc(gs3) m(Oh)) ///
	ci6opts(lc(gs3)) ///
	plot7opts(lc(black) mc(black) m(Th) lwidth(0.5)) ///
	ci7opts(lc(black)) ///
	ytitle(" ", s(small))  ///
	ylab(0.2(.2).8,format(%3.2f) nogrid labs(vsmall)) ///
	xlabel(-2 `""-2" "SD""' -1 `""-1" "SD""' ///
	0 "Mean" 1 `""+1" "SD""' 2 `""+2" "SD""', labs(vsmall)) ///
	xti("") ///
	legend( ///
	pos(6) size(small) row(2)) ///
	yline(0.50, lp(shortdash) lc(gs5)) ///
	graphregion(color(white)) ///
	legend(off) ///
	name(int_actors_trustindustry, replace) 


*Note: Add in Latex 
*Marginal means from conjoint experiment for the dimension 'actors involved in the policy design process'. Dependent variable is the choice based on preference towards a policy proposal (A or B). Marginal means are conditioned by subgroups of different types of trust towards these actors (−2 s.d. to +2 s.d.). The grey dashed line denotes the 50% probability of selecting a proposal with the given characteristics controlling for all other policy dimensions. Error bars in represent 95% confidence intervals (df=`df') from `n' respondents * 5 choices for n=`obs' observations
	

gr combine ///
	int_actors_trustinst ///
	int_actors_trustuniv ///
	int_actors_trustngo ///
	int_actors_trustindustry, ///
	col (2) ///
	note("",  ///
	s(tiny) pos(7)) ///
	graphregion(color(white)) ///
	name(fig_trust_actors2, replace)

graph di, ysize(100) xsize(70)
	
//Save Figure 
graph export "Plots\Figure3b_interaction.png", name("fig_trust_actors2") replace width(3000)

graph export "Plots\Figure3b_interaction_binary.pdf", as(pdf) name("fig_trust_actors2") replace	
	